Skip to content

fix(client): use authenticatedFetch in update-adapter#91

Merged
DJJones66 merged 1 commit intofeature/braindrive-update-notification-library-migrationfrom
fix/update-adapter-authenticated-fetch
Apr 24, 2026
Merged

fix(client): use authenticatedFetch in update-adapter#91
DJJones66 merged 1 commit intofeature/braindrive-update-notification-library-migrationfrom
fix/update-adapter-authenticated-fetch

Conversation

@davewaring
Copy link
Copy Markdown
Member

Summary

  • Swap fetchauthenticatedFetch in update-adapter.ts so protected update routes get the Bearer access token in local auth mode
  • Removes explicit buildLocalOwnerHeaders() call (the authenticatedFetch wrapper handles auth headers internally, matching the pattern used by gateway-adapter.ts)

Why

During end-to-end testing of this branch against a fresh-owner install, clicking the sidebar Update available indicator 401'd on POST /api/updates/conversation/start. Root cause: update-adapter.ts used plain fetch() without a Bearer header. GET /api/updates/status happens to work because it's in the publicRoutes set, so the sidebar indicator rendered fine — but the moment the owner clicked it, the protected route rejected the request.

Every other authed client adapter in this repo (see gateway-adapter.ts) goes through authenticatedFetch, which:

  • attaches the Bearer token in local mode
  • falls back to local-owner headers in local-owner mode
  • transparently refreshes the access token on 401

This PR brings update-adapter.ts in line with that pattern.

See the broader test-pass write-up and design decisions in community thread 250, post #7: https://community.braindrive.ai/t/braindrive-update-system/250/7

Test plan

  • Fresh-owner flow: reset dev volumes, sign up as new user, click "Update available" → confirmed POST /api/updates/conversation/start returns 200 with status: started, bootstrap_sent: true
  • Existing-owner flow: not yet retested under this fix (blocked on Q18 skill wiring / OQ-6)
  • local-owner auth mode: not yet explicitly tested — authenticatedFetch is supposed to cover both modes via its mode-switch branch, but worth a smoke check if you exercise that path

Related

🤖 Generated with Claude Code

POST /api/updates/conversation/start was returning 401 in local auth mode
because update-adapter used plain fetch() + buildLocalOwnerHeaders(), which
works for public routes (GET /updates/status is in the publicRoutes set) but
does not attach the Bearer access token required for protected routes.

Swap to authenticatedFetch from auth-adapter.ts — it handles the Bearer
token in local mode and merges in local-owner headers when auth_mode is
local-owner, matching the pattern used by every other authed client adapter
(see gateway-adapter.ts).

Verified by running the fresh-owner flow on the branch: clicking
"Update available" now returns 200 with status: started, bootstrap_sent: true.
See thread 250 post #7 for the broader test-pass context.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@DJJones66 DJJones66 merged commit b4742e4 into feature/braindrive-update-notification-library-migration Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants